//
//  AXFCouponController.m
//  BeeQuick
//
//  Created by 王誉升 on 2016/11/19.
//  Copyright © 2016年 six_group. All rights reserved.
//

#import "AXFCouponController.h"
#import "AXFUserDetailController.h"
#import "AXFCouponCell.h"
#import "AXFNextCouponCell.h"

static NSString *couponCell = @"couponCellID";
static NSString *nextCouponCell = @"nextCouponCellID";
@interface AXFCouponController ()<UITableViewDelegate,UITableViewDataSource>

@property (nonatomic,weak) UITableView *tableView;

@end

@implementation AXFCouponController

- (void)viewDidLoad
{
    [super viewDidLoad];
    
    [self setupUI];
}

- (void)setupUI
{
    
    self.view.backgroundColor = [UIColor whiteColor];
    
    self.navigationItem.title = @"优惠劵";
    
    //设置navigationItem的右侧按钮
    UIBarButtonItem *rightBarButton = [[UIBarButtonItem alloc] initWithTitle:@"使用规则" style:UIBarButtonItemStylePlain target:self action:@selector(clickToDetailVC)];
    
    rightBarButton.tintColor = [UIColor grayColor];
    
    [rightBarButton setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:[UIFont boldSystemFontOfSize:15],NSFontAttributeName,nil] forState:UIControlStateNormal];
    
    self.navigationItem.rightBarButtonItem = rightBarButton;
    
    //自定义导航条返回按钮
    UIBarButtonItem *leftBarButton = [[UIBarButtonItem alloc]initWithImage:[UIImage imageNamed:@"v2_goback"] style:UIBarButtonItemStylePlain target:self action:@selector(clickToVC:)];
    
    self.navigationItem.leftBarButtonItem = leftBarButton;
}

- (void)clickToVC:(UIBarButtonItem *)batBtn
{
    
    [self.navigationController popViewControllerAnimated:YES];
    
}

#pragma mark - 使用规则按钮点击事件
- (void)clickToDetailVC{
    
    AXFUserDetailController *userDetailVC = [[AXFUserDetailController alloc]init];
    
    [self.navigationController pushViewController:userDetailVC animated:YES];
}

#pragma mark - 数据源方法
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 2;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    if(section == 1)
    {
        return 5;
    }
    return 1;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if(indexPath.section == 0)
    {
        AXFCouponCell *cell = [tableView dequeueReusableCellWithIdentifier:couponCell forIndexPath:indexPath];
    }
    
    AXFNextCouponCell *cell = [tableView dequeueReusableCellWithIdentifier:nextCouponCell forIndexPath:indexPath];
    
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    
    return cell;
}

- (void)viewWillAppear:(BOOL)animated
{
    //设置navigationItem
    [self.navigationController setNavigationBarHidden:NO animated:YES];
    
    self.tabBarController.tabBar.hidden = YES;
    
    //设置输入优惠券视图
    UIView *importView = [[UIView alloc]init];
    
    importView.backgroundColor = [UIColor whiteColor];
    
    [self.view addSubview:importView];
    
    //设置约束
    [importView mas_makeConstraints:^(MASConstraintMaker *make) {
       
        make.top.equalTo(self.view).offset(64);
        
        make.right.left.equalTo(self.view);
        
        make.height.mas_equalTo(55);
        
    }];
    
    UITextField *textF = [[UITextField alloc]init];
    
    [importView addSubview:textF];
    
    [textF mas_makeConstraints:^(MASConstraintMaker *make) {
       
        make.top.equalTo(importView).offset(15);
        
        make.left.equalTo(importView).offset(20);
        
        make.width.mas_equalTo(240);
        
        make.height.mas_equalTo(30);
        
    }];
    
    textF.placeholder = @"请输入优惠券号码";
    
    //设置右侧绑定按钮
    UIButton *button = [[UIButton alloc]init];
    
    [button setTitle:@"绑定" forState:UIControlStateNormal];
    
    [button setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    
    [button setBackgroundColor:[UIColor yellowColor]];
    
    button.titleLabel.font = [UIFont systemFontOfSize:16];
    
    [importView addSubview:button];
    
    //设置约束
    [button mas_makeConstraints:^(MASConstraintMaker *make) {
       
        make.centerY.equalTo(textF);
        
        make.left.equalTo(textF.mas_right).offset(15);
        
        make.right.equalTo(importView).offset(-25);
    }];
    
    //设置购物券视图
    UITableView *couponTableV = [[UITableView alloc]init];
    
    [self.view addSubview:couponTableV];
    
    [couponTableV mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.equalTo(importView.mas_bottom).offset(1);
        
        make.left.right.equalTo(importView);
        
        make.height.equalTo(self.view);
        
    }];
    
    //设置TableView代理
    couponTableV.delegate = self;
    couponTableV.dataSource = self;
    
    couponTableV.rowHeight = 100;
    
    //注册cell
    [couponTableV registerNib:[UINib nibWithNibName:@"AXFCouponCell" bundle:[NSBundle mainBundle]] forCellReuseIdentifier:couponCell];
    
    [couponTableV registerNib:[UINib nibWithNibName:@"AXFNextCouponCell" bundle:[NSBundle mainBundle]] forCellReuseIdentifier:nextCouponCell];
}

- (void)viewWillDisappear:(BOOL)animated
{
    self.tabBarController.tabBar.hidden = NO;
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    
}

@end
